
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<style>
    #selectPODiv .modal-dialog{
        margin: 80px auto;
    }
    #selectPODiv .form-group select, #selectPODiv .form-group input {
        width: calc(100vw / 2 - 400px);
    }
    .btn-warning.btn-outline {
        color: #fff;
    }
    .btn-submit{
        background: #2c74fa;
        margin-left: 20px;
        border: none;
        color: #fff;
    }
</style>

<div class="modal" id="selectPODiv" tabindex="-1" role="dialog" aria-hidden="true" style="width: auto;">

    <div class="modal-dialog modal-lg" role="document">

        <div class="modal-content animated bounceInRight">

            <div class="modal-header">
                <h4 class="modal-title">采购订单选择</h4>
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body" style="padding-bottom: 20px; padding-top: 5px;">

                <jsp:include page="../search/poSearch.jsp"></jsp:include>

                <div class="table-responsive">

                    <div class="col-sm-12 text-right" style="padding-right: 0px;">
                        <button id="searchConfirmButton" type="button" class="btn btn-success btn-sm" style="margin-bottom: 5px; display: none;">查询</button>
                        <button id="searchButton" class="btn btn-default btn-sm" type="button" style="margin-bottom: 5px;"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
                    </div>

                    <table class="table table-striped table-hover table-bordered border-top">
                        <thead>
                        <tr>
                            <th></th>
                            <th>订单编码</th>
                            <th>发货单编码</th>
                            <th>供应商</th>
                            <th>供应商联系人</th>
                            <th>配送方式</th>
                            <th>是否有发票</th>
                            <th>票据类型</th>
                            <th>状态</th>
                        </tr>
                        </thead>
                        <tbody>

                        <c:forEach items="${requestScope.deliveryNoteHeadList}" var="data" varStatus="status">
                            <tr>
                                <td><input type="checkbox" class="i-checks" name="input[]"></td>
                                <td class="poCode">${data.code}</td>
                                <td class="deliveryCode">${data.purchase_order_id}</td>
                                <td class="supplier">${data.vendor_name}</td>
                                <td class="contacts">${data.contact_name}</td>
                                <td class="deliveryMethod">1</td>
                                <td class="isInvoice">1</td>
                                <td>1</td>
                                <td>1</td>
                            </tr>
                        </c:forEach>

                        </tbody>
                        <tfoot>
                        <%-- 导入页码 --%>
                        <jsp:include page="../../common/popPages.jsp"></jsp:include>
                        </tfoot>
                    </table>
                </div>
                <div class="col-md-12">
                    <div class="form-group row m-b-none">
                        <div class="col-sm-10 col-sm-offset-2 text-right">
                            <button class="btn btn-white btn-lg" type="button" data-dismiss="modal">返回</button>
                            &nbsp;
                            <button id="selectButton" class="btn btn-submit" data-style="expand-right">
                               确定
                            </button>
                        </div>
                    </div>
                </div>

            </div>

        </div>

    </div>

</div>

<script>
    $(document).ready(function() {
        //初始化checkbox
        $('.i-checks').iCheck({
            checkboxClass : 'icheckbox_square-green',
            radioClass : 'iradio_square-green',
        });


        //checkbox选中效果
        $("tr").click(function(){
            if($(this).find(".i-checks").prop("checked")){
                $(this).find(".i-checks").iCheck('uncheck');
            }else{
                $(".i-checks").iCheck('uncheck');
                $(this).find(".i-checks").iCheck('check');
            }

        });

        //查询条件
        $("#searchButton").click(function() {
            if ($("#searchDiv").css("display") == "none") {
                $("#searchDiv").show();
                $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;关闭查询');
                $("#searchButton").addClass("btn-outline btn-warning");
                $("#searchButton").blur();
                $("#searchConfirmButton").show();
            } else {
                $("#searchDiv").hide();
                $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;展开查询');
                $("#searchButton").removeClass("btn-outline btn-warning");
                $("#searchButton").blur();
                $("#searchConfirmButton").hiden();
            }
        });

        //确认按钮
        $("#selectButton").click(function(){
            if($("#lineTab table tbody tr").length>0){
                redragonJS.alert("选择前必须删除所有行信息");
            }else{
                var selectFlag = "N"
                var deliveryCode =  "";
                var deliveryName = "";
                var supplier = "";
                var contacts = "";
                var deliveryMethod = "";

                $('.i-checks').each(function(){
                    if($(this).prop("checked")){
                        selectFlag = "Y";
                        deliveryCode = $(this).parents("tr").find("td.deliveryCode").text();
                        deliveryName = $(this).parents("tr").find("td.deliveryName").text();
                        supplier = $(this).parents("tr").find("td.supplier").text();
                        contacts = $(this).parents("tr").find("td.contacts").text();
                        deliveryMethod = $(this).parents("tr").find("td.deliveryMethod").text();
                        return false;
                    }
                });

                if(selectFlag=="N"){
                    redragonJS.alert("必须选择一个采购订单");
                }else{
                    $("#vendorName").val(supplier);
                    $("#vendorContactDesc").val(contacts);
                    $("#inputSourceHeadCode").val(deliveryCode);
                    $("#inputSourceHeadName").val(deliveryName);
                    $('#selectPODiv').modal('hide');
                    $("#inputSourceType").val(deliveryMethod);
                }
            }
        });
    });

    //跳转页面
    function gotoPage(page){
        var pageNumber = ${requestScope.pages.pageNumber};
        var currentPage = ${requestScope.pages.page};
        //首页和尾页无需跳转
        if((currentPage==1&&page==1)||(currentPage==pageNumber&&page==pageNumber)){

        }else{
            getSelectPOModal(page);
        }
    }
</script>